package br.inf.solutions.apresentacoes.ssp.model;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.com.vexillum.model.CommonEntityActivated;
import br.com.vexillum.model.annotations.SearchField;
import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.inf.solutions.apresentacoes.ssp.model.basics.Model;
import br.inf.solutions.apresentacoes.ssp.model.enums.DirectionRays;
import br.inf.solutions.apresentacoes.ssp.model.enums.TypeBarrel;
import br.inf.solutions.apresentacoes.ssp.model.hierarchy.HierarchyStructEntity;

@SuppressWarnings("serial")
@ValidatorClass(validatorClass = "br.inf.solutions.apresentacoes.ssp.control.validator.WeaponValidator")
@Entity
@Table(name = "weapon")
public class Weapon extends CommonEntityActivated {

	public Weapon() {
		this.stealth = false;
		this.typeWeapon = new TypeWeapon();
	}
	
	@SearchField
	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_model", nullable = false, updatable = true, unique = false)
	private Model model;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_species", nullable = false, updatable = true, unique = false)
	private Species species;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_caliber", nullable = false, updatable = true, unique = false)
	private Caliber caliber;

	@Validate(notNull = false)
	@Column(name = "manufacture_year", nullable = true, unique = false, updatable = true)
	private Integer manufactureOfYear;

	@Validate(notNull = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_countrymanufacture", nullable = true, updatable = true, unique = false)
	private CountryOfManufacture countryOfManufacture;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_typeweapon", nullable = false, updatable = true, unique = false)
	private TypeWeapon typeWeapon;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_functioning", nullable = false, updatable = true, unique = false)
	private Functioning functioning;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_finishing", nullable = false, updatable = true, unique = false)
	private Finishing finishing;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_resource", nullable = false, updatable = true, unique = false)
	private Resource resource;

	@Validate(notNull = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_preservation", nullable = true, updatable = true, unique = false)
	private Preservation preservation;

	@Validate(notNull = true)
	@Column(name = "amount_barrel", nullable = false, unique = false, updatable = true)
	private Integer amountBarrel;

	@Validate(notNull = false)
	@Column(name = "size_barrel", nullable = true, unique = false, updatable = true)
	private Integer sizeBarrel;

	@Validate(notNull = false)
	@Column(name = "type_size_barrel", nullable = true, unique = false, updatable = true)
	@Enumerated(EnumType.STRING)
	private TypeBarrel typeOfSizeBarrel;

	@Validate(notNull = false)
	@Column(name = "amount_rays", nullable = true, unique = false, updatable = true)
	private Integer amountRays;

	@Validate(notNull = false)
	@Column(name = "direction_rays", nullable = true, unique = false, updatable = true)
	@Enumerated(EnumType.STRING)
	private DirectionRays directionRays;

	@Validate(notNull = false)
	@Column(name = "capacity", nullable = true, unique = false, updatable = true)
	private Integer capacity;

	@Validate(notNull = false)
	@Column(name = "number_sigma", nullable = true, unique = false, updatable = true)
	private String numberOfSigma;

	@Validate(notNull = false)
	@Column(name = "acquisition_date", nullable = true, unique = false, updatable = true)
	private Date acquisitionDate;

	@Validate(notNull = false)
	@Column(name = "number_official_daily", nullable = true, unique = false, updatable = true)
	private String numberOfficialDaily;

	@Validate(notNull = false)
	@Column(name = "unitary_value_acquisition", nullable = true, unique = false, updatable = true)
	private Double unitaryValueOfAcquisition;

	@Validate(notNull = false)
	@Column(name = "number_patrimony", nullable = true, unique = false, updatable = true)
	private String numberOfPatrimony;

	@Validate(notNull = false)
	@Column(name = "number_fiscal_note", nullable = true, unique = false, updatable = true)
	private String numberOfFiscalNote;

	@Validate(notNull = false)
	@Column(name = "code_rfid", nullable = true, unique = false, updatable = true)
	private String codeRFID;

	@Validate(notNull = true)
	@Column(name = "number_weapon", nullable = false, unique = false, updatable = true)
	private String numberWeapon;

	@Validate(notNull = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_ownerweapon", nullable = true, updatable = true, unique = false)
	private OwnerWeapon ownerWeapon;

	@Validate(notNull = false)
	@Column(name = "ownerweapon_name", nullable = true, unique = false, updatable = true)
	private String ownerWeaponName;

	@Validate(notNull = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_provider", nullable = true, updatable = true, unique = false)
	private Provider provider;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "unity", nullable = false, updatable = true, unique = false)
	private HierarchyStructEntity unity;
		
	@Cascade(CascadeType.ALL)
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "weapon", targetEntity = ItensStealthWeapon.class)
	private List<ItensStealthWeapon> itensStealthWeapon;
	
	@Validate(notNull = false)
	@Column(name = "stealth", nullable = true, unique = false, updatable = true)
	private Boolean stealth;
	
	@Transient
	private Long numberEffective;
	
	@Override
	public String toString() {
		return getNumberWeapon().toString() + " - " + getModel().getMark().getName() + " - " + getModel().getName() ;
	}
	
	public Long getNumberEffective() {
		return numberEffective;
	}
	
	public void setNumberEffective(Long numberEffective) {
		this.numberEffective = numberEffective;
	}

	public Boolean getStealth() {
		return stealth;
	}

	public void setStealth(Boolean stealth) {
		this.stealth = stealth;
	}

	public Model getModel() {
		return model;
	}

	public void setModel(Model model) {
		this.model = model;
	}

	public Species getSpecies() {
		return species;
	}

	public void setSpecies(Species species) {
		this.species = species;
	}

	public Caliber getCaliber() {
		return caliber;
	}

	public void setCaliber(Caliber caliber) {
		this.caliber = caliber;
	}

	public Integer getManufactureOfYear() {
		return manufactureOfYear;
	}

	public void setManufactureOfYear(Integer manufactureOfYear) {
		this.manufactureOfYear = manufactureOfYear;
	}

	public CountryOfManufacture getCountryOfManufacture() {
		return countryOfManufacture;
	}

	public void setCountryOfManufacture(
			CountryOfManufacture countryOfManufacture) {
		this.countryOfManufacture = countryOfManufacture;
	}

	public TypeWeapon getTypeWeapon() {
		return typeWeapon;
	}

	public void setTypeWeapon(TypeWeapon typeWeapon) {
		this.typeWeapon = typeWeapon;
	}

	public Functioning getFunctioning() {
		return functioning;
	}

	public void setFunctioning(Functioning functioning) {
		this.functioning = functioning;
	}

	public Finishing getFinishing() {
		return finishing;
	}

	public void setFinishing(Finishing finishing) {
		this.finishing = finishing;
	}

	public Resource getResource() {
		return resource;
	}

	public void setResource(Resource resource) {
		this.resource = resource;
	}

	public Preservation getPreservation() {
		return preservation;
	}

	public void setPreservation(Preservation preservation) {
		this.preservation = preservation;
	}

	public Integer getAmountBarrel() {
		return amountBarrel;
	}

	public void setAmountBarrel(Integer amountBarrel) {
		this.amountBarrel = amountBarrel;
	}

	public Integer getSizeBarrel() {
		return sizeBarrel;
	}

	public void setSizeBarrel(Integer sizeBarrel) {
		this.sizeBarrel = sizeBarrel;
	}

	public TypeBarrel getTypeOfSizeBarrel() {
		return typeOfSizeBarrel;
	}

	public void setTypeOfSizeBarrel(TypeBarrel typeOfSizeBarrel) {
		this.typeOfSizeBarrel = typeOfSizeBarrel;
	}

	public Integer getAmountRays() {
		return amountRays;
	}

	public void setAmountRays(Integer amountRays) {
		this.amountRays = amountRays;
	}

	public DirectionRays getDirectionRays() {
		return directionRays;
	}

	public void setDirectionRays(DirectionRays directionRays) {
		this.directionRays = directionRays;
	}

	public Integer getCapacity() {
		return capacity;
	}

	public void setCapacity(Integer capacity) {
		this.capacity = capacity;
	}

	public String getNumberOfSigma() {
		return numberOfSigma;
	}

	public void setNumberOfSigma(String numberOfSigma) {
		this.numberOfSigma = numberOfSigma;
	}

	public Date getAcquisitionDate() {
		return acquisitionDate;
	}

	public void setAcquisitionDate(Date acquisitionDate) {
		this.acquisitionDate = acquisitionDate;
	}

	public String getNumberOfficialDaily() {
		return numberOfficialDaily;
	}

	public void setNumberOfficialDaily(String numberOfficialDaily) {
		this.numberOfficialDaily = numberOfficialDaily;
	}

	public Double getUnitaryValueOfAcquisition() {
		return unitaryValueOfAcquisition;
	}

	public void setUnitaryValueOfAcquisition(Double unitaryValueOfAcquisition) {
		this.unitaryValueOfAcquisition = unitaryValueOfAcquisition;
	}

	public String getNumberOfPatrimony() {
		return numberOfPatrimony;
	}

	public void setNumberOfPatrimony(String numberOfPatrimony) {
		this.numberOfPatrimony = numberOfPatrimony;
	}

	public String getNumberOfFiscalNote() {
		return numberOfFiscalNote;
	}

	public void setNumberOfFiscalNote(String numberOfFiscalNote) {
		this.numberOfFiscalNote = numberOfFiscalNote;
	}

	public String getCodeRFID() {
		return codeRFID;
	}

	public void setCodeRFID(String codeRFID) {
		this.codeRFID = codeRFID;
	}

	public String getNumberWeapon() {
		return numberWeapon;
	}

	public void setNumberWeapon(String numberWeapon) {
		this.numberWeapon = numberWeapon;
	}

	public OwnerWeapon getOwnerWeapon() {
		return ownerWeapon;
	}

	public void setOwnerWeapon(OwnerWeapon ownerWeapon) {
		this.ownerWeapon = ownerWeapon;
	}

	public HierarchyStructEntity getUnity() {
		return unity;
	}

	public void setUnity(HierarchyStructEntity unity) {
		this.unity = unity;
	}

	public List<ItensStealthWeapon> getItensStealthWeapon() {
		return itensStealthWeapon;
	}

	public void setItensStealthWeapon(List<ItensStealthWeapon> itensStealthWeapon) {
		this.itensStealthWeapon = itensStealthWeapon;
	}

	public Provider getProvider() {
		return provider;
	}

	public void setProvider(Provider provider) {
		this.provider = provider;
	}

	public String getOwnerWeaponName() {
		return ownerWeaponName;
	}

	public void setOwnerWeaponName(String ownerWeaponName) {
		this.ownerWeaponName = ownerWeaponName;
	}
}